package flc.ast.fragment;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.view.View;

import java.util.ArrayList;
import java.util.List;

import flc.ast.R;
import flc.ast.adapter.RecordAdapter;
import flc.ast.bean.MyRecordBean;
import flc.ast.databinding.FragmentRecordBinding;
import flc.ast.utils.AppSpUtils;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.event.EventStatProxy;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link RecordFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class RecordFragment extends BaseNoModelFragment<FragmentRecordBinding> {

    private List<MyRecordBean> listShow = new ArrayList<>();
    private RecordAdapter recordAdapter;

    @Override
    protected int onCreate() {
        return R.layout.fragment_record;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(getActivity(), mDataBinding.event1Container);
        EventStatProxy.getInstance().statEvent5(getActivity(), mDataBinding.event5Container);
    }

    @Override
    protected void initData() {
        mDataBinding.rvRecordList.setLayoutManager(new LinearLayoutManager(mContext));
        recordAdapter = new RecordAdapter();
        mDataBinding.rvRecordList.setAdapter(recordAdapter);
    }

    @Override
    public void onResume() {
        super.onResume();
        getData();
    }

    private void getData() {
        if (listShow != null) {
            listShow.clear();
        }
        listShow = AppSpUtils.getRecordList();
        if (listShow != null && listShow.size() != 0) {
            recordAdapter.setList(listShow);
            mDataBinding.rvRecordList.setVisibility(View.VISIBLE);
            mDataBinding.tvRecordNoData.setVisibility(View.GONE);
        } else {
            mDataBinding.rvRecordList.setVisibility(View.GONE);
            mDataBinding.tvRecordNoData.setVisibility(View.VISIBLE);
        }
    }

}